<?php
$dbc = mysqli_connect('localhost', 'online_shopper', 'shop', 'online_shop')
or die('Error connecting to db');

$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$dateofbirth = $_POST['dateofbirth'];
$gender = $_POST['gender'];
$password = sha1($_POST['pwd']);
$login = $_POST['login'];

$query = "insert into Person(firstName, lastName, dateOfBirth, gender)".
       "VALUES('$first_name', '$last_name', '$dateofbirth', '$gender')";
mysqli_query($dbc,$query) or die('Error querying database');
echo 'Customer added.';

$queryid = "select iD from Person".
	 " where firstName = '$first_name' and lastName = '$last_name'";

$result = mysqli_query($dbc, $queryid) or die('Error querying getting result');
$row = mysqli_fetch_array($result);
$personID = $row['iD'];
$queryLogin = "insert into Login(personID, login, pwd)".
	    "values('$personID', '$login', '$password')";
mysqli_query($dbc, $queryLogin) or die('Error adding login');

mysqli_close($dbc);
?>
